package controllers

import (
	"fengxian/models"
	beego "github.com/beego/beego/v2/server/web"
)

type JsonR struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}
type HouseController struct {
	beego.Controller
}

func (c *HouseController) List() {
	var house []models.House
	err := models.DB.Model(&models.House{}).Find(&house).Error
	if err != nil {
		c.Data["json"] = JsonR{
			Code: 500,
			Msg:  "查询失败",
			Data: nil,
		}
		c.ServeJSON()
	} else {
		c.Data["json"] = JsonR{
			Code: 200,
			Msg:  "查询成功",
			Data: house,
		}
		c.ServeJSON()
	}
}
